package com.wxp.util;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.multipart.MultipartFile;

public class FileComutils {
	public static String upload(MultipartFile file, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		String path = request.getSession().getServletContext().getRealPath("upload");
		String fixString = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
		String fileName = UuidUtil.get32UUID() + fixString;
		File dir = new File(path, fileName);
		if (!dir.exists()) {
			dir.mkdirs();
		}
		file.transferTo(dir);
		return fileName + "," + file.getOriginalFilename();
	}

}
